package canss.webservice.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import canss.supports.basic;
import canss.webservice.service.PortalIntraWebServiceControl;
import canss.webservice.service.PortalIntraWebServiceControlBean;

public class svtAjaxAddEvent extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet
{
	private static final long serialVersionUID = -2400208041205912489L;

	public svtAjaxAddEvent()
	{
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		doPost(request, response);
	}

	PortalIntraWebServiceControl control;

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out = response.getWriter();

		String _mid = request.getParameter("_mid");
		String _eventid = request.getParameter("_eventid");
		String _timestamp = request.getParameter("_timestamp");
		String _extradata = request.getParameter("_extradata");
		
		if( !basic.isEmpty(_mid) &&
			!basic.isEmpty(_eventid) &&
			!basic.isEmpty(_timestamp) &&
			!basic.isEmpty(_extradata) )
		{
			control = (control == null) ? new PortalIntraWebServiceControlBean() : control;
			Boolean ret = control.addNewEvent(_mid, Integer.parseInt(_eventid), Long.parseLong(_timestamp), _extradata);
			if(ret!=null)
				out.write(ret.toString());
			else
				out.write("null");
		}
		
		String _rurl = request.getParameter("_rurl");
		if (!basic.isEmpty(_rurl))
		{
			response.sendRedirect(response.encodeRedirectURL(_rurl));
		}
	}
}